package com.example.broad;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class BroadActivity extends AppCompatActivity {
 Button bt;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad);
        bt=findViewById(R.id.button);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //广播静态注册文件中需声明
                Intent it=new Intent();
                it.putExtra("序号",1);
                it.setAction("com.mybroadcast");
            //android8.0以后不支持隐士接收者
                ComponentName compon=new ComponentName(getApplicationContext(),"com.example.broad");//参数1-包名 参数2-广播接收者所在的路径名

                it.setComponent(compon);
                sendBroadcast(it);
                 //1.设置广播的接收者
                /*MyReceiver myd=new MyReceiver();

                // 2. 设置接收广播的类型
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.setPriority(100);
                intentFilter.addAction("com.pateo.mybroadcast");
                // 3. 动态注册：调用Context的registerReceiver（）方法
                  registerReceiver(myd,intentFilter);*/

















            }
        });
    }
}
